<?php
/**
 * 扩展
 */

namespace app\api\model;
use think\Model;

class Extend extends Model
{
    /**
    * IOS描述性文件udid获取回调
    */
    public function _getUdid($udid){
        if(empty($udid)){
            $msg = json_encode(['time'=>date("Y-m-d H:i:s"), 'udid'=>$udid, 'msg'=>'用户udid不能为空']);
            file_put_contents("udid", $msg, FILE_APPEND);
            return false;
        }
        
        $model = new Udid();
        $data = [
            'udid' => $udid,
            'created' => time()
        ];
        
        $ret = $model->save($data);
        if(!$ret){
            $msg = json_encode(['time'=>date("Y-m-d H:i:s"), 'udid'=>$udid, 'msg'=>'用户udid写入失败']);
            file_put_contents("udid", $msg, FILE_APPEND);
            return false;
        }
        
        return true;
    }
    
    /**
    * 校验用户传入的udid是否存在
    */
    public function _checkExistUdid($udid){
        if(empty($udid)){
            $this->error = '缺失udid';
            return false;
        }
        
        $data = Udid::where([['udid', '=', $udid]])->find();
        if(empty($data)){
            $this->error = "该udid不存在";
            return false;
        }
        
        return true;
    }
    

}